#!/bin/bash
# 软件包安装前执行的脚本
arch=`uname -m`
client=pings_linux-amd64.zip
if [[ $arch == "aarch64" ]];then
  client=pings_linux-arm64.zip
elif [ $arch == "x86_64" ]; then
  client=pings_linux-amd64.zip
elif [ $arch == "mips64" ]; then
  client=pings_linux-mips64le.zip
elif [ $arch == "mips64le" ]; then
  client=pings_linux-mips64le.zip
else
  echo "架构不匹配,安装结束..."
  rm -rf /opt/apps/com.liumou.pings
  exit 1
fi
#mkdir -p /opt/apps/com.liumou.pings/files/

f=/opt/apps/com.liumou.pings/files/${client}
if [[ ! -f $f ]];then
  echo "找不到文件: $f"
  exit 5
fi
p=/usr/sbin/pings
if [[ -f $p ]];then
  rm -f $p
fi
echo "ln -s $f $p"
ln -s $f $p
if [[ $? -eq 0 ]];then
  echo -e "installed successfully"
  chmod 0755 ${p}
  # 在安装或升级过程中执行自定义操作
  exit 0
else
  echo "软连接创建失败..."
  echo "ln -s $f $p"
  exit 2
fi
